import 'package:aichat_flutter_wallet/module/module_news/model/news_detail_model.dart';
import 'package:aichat_flutter_wallet/module/module_news/utils/news_util.dart';
import 'package:aichat_flutter_wallet/module_common/utils/colors.dart';
import 'package:aichat_flutter_wallet/module_common/widgets/image/public_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class NewsDetailHeader extends StatefulWidget {
  NewsDetailModel newsDetailModel;
  int? target_type;
  NewsDetailHeader({Key? key, required this.newsDetailModel, this.target_type})
      : super(key: key);

  @override
  _NewsDetailHeaderState createState() => _NewsDetailHeaderState();
}

class _NewsDetailHeaderState extends State<NewsDetailHeader> {
  @override
  Widget build(BuildContext context) {
    if (widget.target_type != 1 && widget.target_type != 2) {
      return Container(
        child: Column(
          children: [
            Text(
              widget.newsDetailModel.title!,
              style: TextStyle(fontSize: 20.sp, color: AppColors.c_333333),
            ),
            SizedBox(
              height: 20.w,
            ),
            Row(
              children: [
                Text(
                  'Source:${widget.newsDetailModel.source}',
                  style: TextStyle(fontSize: 12.sp, color: AppColors.c_6A6A6A),
                ),
                SizedBox(
                  width: 20.w,
                ),
                Text(
                  widget.newsDetailModel.created_at.isNotEmpty
                      ? NewsUtil.transDate(widget.newsDetailModel.created_at)
                      : '------',
                  style: TextStyle(fontSize: 12.sp, color: AppColors.c_BEBDCA),
                )
              ],
            )
          ],
        ),
      );
    } else {
      return Container(
        child: Row(
          children: [
            ClipRRect(
              borderRadius: BorderRadius.circular(40),
              child: PublicImage(
                image: widget.newsDetailModel.profile_picture,
              ),
            ),
            SizedBox(
              width: 10.w,
            ),
            Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  widget.newsDetailModel.nickname.isEmpty
                      ? '----'
                      : widget.newsDetailModel.nickname,
                  style: TextStyle(
                    fontSize: 16.sp,
                  ),
                ),
                Text(
                  widget.newsDetailModel.created_at.isNotEmpty
                      ? NewsUtil.transDate(widget.newsDetailModel.created_at)
                      : '------',
                  style: TextStyle(fontSize: 12.sp, color: AppColors.c_BEBDCA),
                )
              ],
            )
          ],
        ),
      );
    }
  }
}
